import service from '@/utils/request'
import {ApiResponse,ListApiResponse} from '@/store/dataType.ts'
/**
 * type只能有一个，可以交叉
 * interface同名的话自动合并，平时建议interface，还可以扩展
 * 
 * 
 * 定义审批的操作按钮，src\views\workflow\model\form\bpmnSimpleModelDesigner\components\src\consts.ts
 */
export const API_BPMN_MODEL = {


        getAllRoleList:():Promise<ApiResponse>=>{
            return service.get('/workflow/model/all-role-list');
        },

        getAllPostList:():Promise<ApiResponse>=>{
            return service.get('/workflow/model/all-post-list');
        },

        getUserSimpleList:():Promise<ApiResponse>=>{
            return service.get('/workflow/model/user-simple-list');
        },

        getDeptSimpleList:():any=>{
            return service.get('/workflow/model/dept-simple-list');
        },

        getDeptTreeSelect:():Promise<ApiResponse>=>{
            return service.get('/workflow/model/dept-tree-select');
        },

        // 查询流程定义列表
        getModelList:(query):Promise<ListApiResponse> =>{
            return service({
                url: '/workflow/model/list',
                method: 'get',
                params: query
            })
        },


        getModel:(id: string) => {return service.get( '/workflow/model/'+ id )},

        // 新增流程模型
        createModel: (data:any):Promise<ApiResponse> => {
            console.log('新增模型',data)
            return service.post('/workflow/model/create', data)},

        updateModel: (data:any):Promise<ApiResponse> => {return service.put('/workflow/model/update', data)},


        updateModelSortBatch:(ids: number[]) => {
            return  service.put(`/bpm/model/update-sort-batch`,
                {params: {
                    ids: ids.join(',')
                }})
            },

        // 部署流程模型
        deployModel:(id: number):Promise<ApiResponse> => {return  service.post('/bpm/model/deploy?id=' + id )},
        updateModelState:(id: number, state: number):Promise<ApiResponse> => {
                const data = {
                    id: id,
                    state: state
                }
            return  service.put( '/bpm/model/update-state',data )
        },


        updateModelBpmn:(data: ModelVO):Promise<ApiResponse> => {return service.put('/bpm/model/update-bpmn', data )},
        deleteModel:(id: string):Promise<ApiResponse> => {return  service.delete('/bpm/model/delete/' + id )},
        cleanModel:(id: string):Promise<ApiResponse> => {return service.delete('/bpm/model/clean/' + id ) },
        // 获取流程图
        getProcessDiagram:(modelId):Promise<ApiResponse>  =>{
            return service({
                url: '/workflow/model/' + modelId,
                method: 'get',
                responseType: 'blob'
            })
        }

}

export interface ModelVO {
  id: number
  formName: string //只是VUE前端展示所用
  key: string //例如leaveProcess
  name: string
  description: string
  category: string
  formType: number
  formId: number
  formCustomCreatePath: string
  formCustomViewPath: string
  processDefinition: ProcessDefinitionVO
  status: number
  remark: string
  createTime: string
  bpmnXml: string
}

export interface ProcessDefinitionVO  {
  id: string
  version: number
  deploymentTIme: string
  suspensionState: number
  formType?: number
}



export interface UserSimpleVO {
  userId: number
  nickName: string
  deptId: number
  postIds: string[]
  phonenumber: string
  avatar: string
  status: number
  dept:DeptSimpleVO
}


export interface DeptSimpleVO {
  deptId: number
  deptName: string
  parentId: number
  leader: number
  status: string

}


export interface RoleSimpleVO {
  roleId: number
  roleName: string
  roleKey: string
  roleSort: number

}

export interface PostSimpleVO {
  postId: number
  postCode: string
  postSort: number
  postName: string

}
